package com.cavy.platform.server.controller;

import com.cavy.platform.server.ResultInfo;
import com.cavy.platform.server.dto.*;
import com.cavy.platform.server.service.PipelineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 唐旭
 * @Date 2018/7/17
 */
@RequestMapping("/workSpace/project/pipeline")
@RestController
public class PipelineController {
    @Autowired
    private PipelineService service;

    //创建
    @PostMapping("create")
    public ResultInfo create(@RequestBody @Valid PipelineCreateDto dto) {
        service.create(dto);
        return ResultInfo.newSuccess();
    }

    //创建git远程流水线
    @PostMapping("createGit")
    public ResultInfo createGit(@RequestBody @Valid GitRemotePipelineCreateDto dto) {
        service.create(dto);
        return ResultInfo.newSuccess();
    }

    //删除
    @PostMapping("delete")
    public ResultInfo delete(@RequestBody @Valid PipelineDeleteDto dto) {
        service.delete(dto);
        return ResultInfo.newSuccess();
    }

    //列表
    @GetMapping("list")
    public List<PipelineDto> list(@Valid PipelineSearchDto dto) {
        return service.list(dto);
    }

    //详情
    @GetMapping("info")
    public PipelineDto info(@Valid PipelineGetInfoDto dto) {
        return service.info(dto);
    }

    //创建步骤
    @PostMapping("addStage")
    public ResultInfo addStage(@RequestBody @Valid StageAddDto dto) {
        service.addStage(dto);
        return ResultInfo.newSuccess();
    }

    //修改步骤
    @PostMapping("modifyStage")
    public ResultInfo modifyStage(@RequestBody @Valid StageModifyDto dto) {
        service.modifyStage(dto);
        return ResultInfo.newSuccess();
    }

    //删除步骤
    @PostMapping("deleteStage")
    public ResultInfo delete(@RequestBody @Valid StageDeleteDto dto) {
        service.deleteStage(dto);
        return ResultInfo.newSuccess();
    }

    //运行
    @PostMapping("run")
    public String run(@RequestBody @Valid PipelineRunDto dto) {
        return service.run(dto);
    }
}
